package 多线程.复习.线程安全;

import java.util.concurrent.ConcurrentHashMap;

public class SynchronizedKey {
    private static class Count{
        int count = 0;
        synchronized void increased(){
            count++;
        }
        synchronized void increased1(){
            //当进入increased1方法，需要再次进入increased方法，如果不支持可重入，就会线程就会一致再次等待，就会死锁
            increased();
        }

        synchronized static void increased2(){
            while (true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName());
            }
        }
    }

    public static void main(String[] args) {
        Count c1 = new Count();
        Count c2 = new Count();
        Count c3 = new Count();
        Thread t1 = new Thread(() -> {
            c1.increased2();
        },"t1");
        Thread t2 = new Thread(() -> {
            c2.increased2();
        },"t2");
        Thread t3 = new Thread(() -> {
            c3.increased2();
        },"t3");
        t1.start();
        t2.start();
        t3.start();
//        ConcurrentHashMap
    }
}
